package com.aiwhose.aiwhosecore.bean.system.table;

import com.mybatisflex.core.query.QueryColumn;
import com.mybatisflex.core.table.TableDef;

import java.io.Serial;

/**
 * 接口日志 表定义层。
 *
 * @author 田国刚
 * @since 1.0.1
 */
public class ApiLogsTableDef extends TableDef {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 接口日志
     */
    public static final ApiLogsTableDef API_LOGS = new ApiLogsTableDef();

    /**
     * 主键，自增。
     */
    public final QueryColumn ID = new QueryColumn(this, "id");

    /**
     * 方法名称
     */
    public final QueryColumn METHOD = new QueryColumn(this, "method");

    /**
     * 访问地址
     */
    public final QueryColumn ADDRESS = new QueryColumn(this, "address");

    /**
     * 创建者
     */
    public final QueryColumn CREATE_BY = new QueryColumn(this, "create_by");

    /**
     * 响应数据
     */
    public final QueryColumn RESPONSE = new QueryColumn(this, "response");

    /**
     * 请求参数
     */
    public final QueryColumn ARGUMENTS = new QueryColumn(this, "arguments");

    /**
     * ip地址
     */
    public final QueryColumn IP_ADDRESS = new QueryColumn(this, "ip_address");

    /**
     * 控制器名称
     */
    public final QueryColumn CONTROLLER = new QueryColumn(this, "controller");

    /**
     * 操作人信息
     */
    public final QueryColumn CREATE_INFO = new QueryColumn(this, "create_info");

    /**
     * 创建时间
     */
    public final QueryColumn CREATE_TIME = new QueryColumn(this, "create_time");

    /**
     * HTTP方法（如GET、POST等）
     */
    public final QueryColumn HTTP_METHOD = new QueryColumn(this, "http_method");

    /**
     * 项目名称
     */
    public final QueryColumn PROJECT_NAME = new QueryColumn(this, "project_name");

    /**
     * 请求路径
     */
    public final QueryColumn REQUEST_PATH = new QueryColumn(this, "request_path");

    /**
     * 执行时间，单位毫秒
     */
    public final QueryColumn EXECUTION_TIME = new QueryColumn(this, "execution_time");

    /**
     * 所有字段。
     */
    public final QueryColumn ALL_COLUMNS = new QueryColumn(this, "*");

    /**
     * 默认字段，不包含逻辑删除或者 large 等字段。
     */
    public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{ID, REQUEST_PATH, HTTP_METHOD, CONTROLLER, METHOD, ARGUMENTS, RESPONSE, EXECUTION_TIME, CREATE_INFO, IP_ADDRESS, PROJECT_NAME, ADDRESS, CREATE_BY, CREATE_TIME};

    public ApiLogsTableDef() {
        super("", "api_logs");
    }

    private ApiLogsTableDef(String schema, String name, String alisa) {
        super(schema, name, alisa);
    }

    public ApiLogsTableDef as(String alias) {
        String key = getNameWithSchema() + "." + alias;
        return getCache(key, k -> new ApiLogsTableDef("", "api_logs", alias));
    }

}
